#ifndef  THREADMUTEX_H_
#define THREADMUTEX_H_

#include <windows.h>

class CLock
{
public:
	virtual void Lock() = 0;
	virtual void UnLock() = 0;
};

class CThreadMutex :
	public CLock
{
	CRITICAL_SECTION	m_crtS;
public:
	CThreadMutex()
	{
#if(_WIN32_WINNT >= 0x0403)
		::InitializeCriticalSectionAndSpinCount(&m_crtS, 4000);
#else
		::InitializeCriticalSection(&m_crtS);
#endif
	}

	~CThreadMutex()
	{
		::DeleteCriticalSection(&m_crtS);
	}

public:
	void Lock();		
	void UnLock();
	void NoLock();
};

inline void CThreadMutex::Lock()
{
	::EnterCriticalSection(&m_crtS);
}

inline void CThreadMutex::UnLock()
{
	::LeaveCriticalSection(&m_crtS);
}

inline void CThreadMutex::NoLock()
{
	::TryEnterCriticalSection(&m_crtS);
}

#endif